package com.jhhc.StormSurgeForecast.StormSurge.Uitl;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
public class FormulaUtil {

    private static final VariableUtil variableUtil = new VariableUtil();
//    private final double gamma = 10.25;//水的重度（kN/m3）
//    private final double b = 19.05;//箱梁宽度（m）
//    private final double c = 2.89;//箱梁高度（m）
//    private final double a = 49.8;//桥跨长度（m）
    //水位 3.82
    //波高 5.89
    //波周期 8.9
    //水深 d (水位 - 床面高程)
    //L 波长
    //waveDirection 波向

    //最大垂向波压力计算 H波高 z水位 m_wave_t波周期 angle波向桥轴线夹角  deltah净空高度  etaMax波峰高度
    public String PV(double b,double d,double gamma,double H,double m_wave_t,
                                              double angle,double etaMax,double deltah,boolean rule){
        if (!rule) {
            H = H * 1.5;
        }

        double angle1 = Math.toRadians(angle);
        double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长
//        double d1 = L/b;
//        double d2 = Math.sin(angle1);
//        double d3 = d1 * d2;
//        double d4 = Math.pow(1+d3,0.25);
//        double d5 = Math.pow(H / L,-0.4);
//        double d6 = etaMax - deltah;
//        double d7 = d6 / H;
//        double d8 = gamma * H;
//        double pv = d4 * d5 * d7 * d8 * 0.65;

        double pv = gamma * H * 0.65 * Math.pow( 1 + L / b * Math.sin(angle1),0.25) *
                Math.pow(H / L,-0.4) * ((etaMax - deltah) / H);
        return String.format("%.2f",pv);
    }
    //最大水平向波压力计算
    public String PH(double d,double gamma,double H, double m_wave_t,double angle,
                                                double etaMax,double deltah, boolean rule){
        if (!rule) {
            H = H * 1.5;
        }
        double angle1 = Math.toRadians(angle);

        double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长

        double mhwp = 2.0 * Math.pow((H / L),-0.35) *
                ((etaMax - deltah) / H) *
                Math.sin(angle1) * gamma * H;

        return String.format("%.2f",mhwp);
    }

    //浮托力计算
    public String FV(double a,double b,double d,double gamma,double H,double m_wave_t,double angle,
                           double etaMax, double deltah,boolean rule){
        if (!rule) {
            H = H * 1.5;

            double angle1 = Math.toRadians(angle);

            double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长

            double byc = 0.1 * Math.pow((1 + ((L / b) * Math.sin(angle1))),0.25) *
                    Math.pow((H / L),-0.4) * ((etaMax - deltah) / H ) * (gamma * H * a * b);

            return String.format("%.2f",byc);
        }
        double angle1 = Math.toRadians(angle);

        double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长

        double byc = 0.045 * Math.pow((1 + ((L / b) * Math.sin(angle1))),0.25) *
                Math.pow((H / L),-0.4) * ((etaMax - deltah) / H ) * (gamma * H * a * b);

        return String.format("%.2f",byc);

    }
    //水平力计算
    public String FH(double a,double c,double d,double gamma, double H,double m_wave_t,double angle,
                                  double etaMax, double deltah,boolean rule){
        if (!rule) {
            H = H * 1.5;
            double angle1 = Math.toRadians(angle);

            double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长

            double hf = 0.075 * Math.pow((1 + ((a / L) * Math.cos(angle1))),-0.25) *
                    Math.pow((H / L),-0.65) * ((etaMax - deltah) / H) * (gamma * H * a * c);

            return String.format("%.2f",hf);
        }
        double angle1 = Math.toRadians(angle);

        double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长

        double hf = 0.048 * Math.pow((1 + ((a / L) * Math.cos(angle1))),-0.25) *
                Math.pow((H / L),-0.65) * ((etaMax - deltah) / H) * (gamma * H * a * c);

        return String.format("%.2f",hf);
    }
    //桥墩基础冲刷评估(水流作用下)
    //type桥墩类型
    public String HBS(int type,double z,double v){
       //double hb = a * KXi * Math.pow(B1,0.35) * Math.pow(h,0.52) * Math.pow(v,0.8);
        double KXi = variableUtil.calculationK(type);

        double B1 = variableUtil.calculationB1(type);

        double d = Double.parseDouble(variableUtil.calculationD(z));//水深

        double hb = 0.14 * KXi * Math.pow(B1,0.35) * Math.pow(d,0.52) * Math.pow(v,0.8);

        return String.format("%.2f",hb);
    }
    //桥墩基础冲刷评估(波流作用下)
    //Kξ 墩型系数  B1 桥墩计算宽度  v流速  H 波高  λ波陡  type桥墩类型  z水位  m_wave_t波周期
    public String HBB(int type, double z,double m_wave_t,double H,double v){

        double KXi = variableUtil.calculationK(type);

        double B1 = Math.pow(variableUtil.calculationB1(type),0.35);

        double d = Double.parseDouble(variableUtil.calculationD(z));//水深

        double sh = Math.pow(d,0.52);

        double ls = Math.pow(v,0.8);

        double bg = Math.pow(H,0.62);

        double L = Double.parseDouble(variableUtil.calculationL(d,m_wave_t));//波长

        double lambda = Math.pow(Double.parseDouble(variableUtil.calculation(H,L)),0.53);//波陡

        double hb = 0.14 * KXi * B1 * (sh * ls + bg * lambda);

        return String.format("%.2f",hb);
    }
    /**
     *
     * @param Kb   平台折减系数Kb 需计算
     * Kdeerta 护面糙渗系数KΔ   港珠澳大桥取0.38
     * @param kexi1  破波参数 ξ1% 需计算
     * @param H1  波高H1%  4
     * @return RF波浪爬高值
     */
    public String RF(double Kb,double kexi1,double H1){
//        System.out.println(Kb);
//        System.out.println(kexi1);
//        System.out.println(H1);
        if (kexi1 <= 1.25) {
            return String.format("%.2f",1.67 * Kb * 0.38 * kexi1 * H1);
        }else {
            return String.format("%.2f",Kb * 0.38 * (2.89 - 0.77 / Math.sqrt(kexi1)) * H1);
        }
    }

    /**
     * 堤顶高程 8
     * 平台高程 3
     * 平台宽度 12
     * @param Hs  有效波高Hs
     * @param Kc  坡肩折减系数Kc 需计算
     * @param Kb  平台折减系数Kb  需计算
     * @param kexi  破波参数 ξ  需计算
     * @param Rc  超高Rc  需计算
     * g = 9.81
     * @return
     */
    public String Q(double Hs,double Kc,double Kb,double kexi,double Rc){
//        System.out.println(Hs);
//        System.out.println(Kc);
//        System.out.println(Kb);
//        System.out.println(kexi);
//        System.out.println(Rc);
        double q = Math.sqrt(9.81 * Math.pow(Hs,3)) *
                0.003 / Math.pow(0.5,4)/ Math.pow(0.38,2) * Kc * Kb * kexi *
                Math.exp(-4.75 * Rc / Hs / kexi / Kb / 0.38);
        System.out.println(q);
        return String.format("%.4f",q);
    }



}
